package main

import (
	"fmt"
	"runtime"
	"sync"
	"time"
)

var wg sync.WaitGroup
var i int

func test() {
	x := 1

	for j := 2; j < 100000000; j++ {
		x += j
	}
	//fmt.Printf("result: %d\n", x)
	i++
	wg.Done()
}

func init() {
	runtime.GOMAXPROCS(1)
}

func main() {
	fmt.Println("start, left 10s to confirm")
	fmt.Printf("cpus:%d\n", runtime.NumCPU())
	fmt.Printf("GOMAXPROCS:%d\n", runtime.GOMAXPROCS(0))

	for j := 0; j < 1000000; j++ {
		go test()
		wg.Add(1)
	}
	for {
		fmt.Printf("main exit, i:%d\n", i)
		fmt.Printf("num of goroutine: %d\n", runtime.NumGoroutine())
		fmt.Printf("GOMAXPROCS:%d\n", runtime.GOMAXPROCS(0))

		time.Sleep(2 * time.Second)
		fmt.Printf("cpus:%d\n", runtime.NumCPU())
	}
	wg.Wait()
}
